package com.rom.sort;

import com.rom.Utils.Random;

import java.util.Arrays;
import java.util.Date;

public class SelectSort {

    public static void main(String[] args) {

//        Thu Nov 23 14:17:38 CST 2023
//        Thu Nov 23 14:17:57 CST 2023
        int arr[] = new int[300000];
        System.out.println(new Date());
        for (int i = 0; i < 300000; i++) {
            arr[i] = Random.random80000();
        }
        selectSort(arr);
        System.out.println(new Date());
//        System.out.println(Arrays.toString(arr));
    }

    public static void selectSort(int[] arr){

        int k,temp;
        for (int i = 0; i < arr.length - 1; i++) {
            //最小值的下标
            k = i;
            for (int j = i+1; j < arr.length-1; j++) {
                if(arr[k]>arr[j]){
                    k = j;
                }
            }
            if(k!=i){
                temp = arr[i];
                arr[i] = arr[k];
                arr[k] = temp;
            }
        }
    }
}
